<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="https://cdn.bootcdn.net/ajax/libs/axios/0.27.2/axios.min.js"></script>
</head>
<body>
    <button id="box">get请求</button>
    <button id="box2">async和await</button>
    <button id="box3">post请求</button>
    <button id="box4">put请求</button>
    <button id="box5">delete请求</button>
    <script>
        document.getElementById('box').onclick= async ()=>{

            try {
                const response = await axios.get('http://localhost:3000/movie',{
                    params:{
                        id:6
                    }
                })
                let a = JSON.stringify(response.data)
                alert(a)
            } catch (error) {
                console.log(error.message)
            }
        }

        document.getElementById('box3').onclick = async ()=>{
            try {
                const response = await axios.post('http://localhost:3000/movie',{
                    name:'洛基',
                    director:'复仇者联盟'
                })
                alert(response.data)
            } catch (error) {
                console.log(error.message);
            }
        }

        document.getElementById('box4').onclick = async ()=>{
            try {
                const response = await axios.put('http://localhost:3000/movie/8',{
                    name:'钢铁侠',
                    director:'小唐尼'
                })
                alert(response.data)
            } catch (error) {
                console.log(error.message)
            }
        }
        
        document.getElementById('box5').onclick = async ()=>{
            try {
                const response = await axios.delete('http://localhost:3000/movie/8',{
                    params:{
                        aaa:123
                    }
                })
                alert(response.data);
            } catch (error) {
                console.log(error.message);
            }
        }
    </script>
</body>
</html>